Skip to content

test(examples): retry background sidecar on transient port-bind flake#1101

Merged
acroca merged 2 commits into
dapr:mainfrom
kshitizj03:fix/1061-demo-actor-port-bind-retry
Jun 30, 2026
Merged

test(examples): retry background sidecar on transient port-bind flake#1101
acroca merged 2 commits into
dapr:mainfrom
kshitizj03:fix/1061-demo-actor-port-bind-retry

Conversation

@kshitizj03

Copy link
Copy Markdown
Contributor

Description

test_demo_actor flakes when the demo-actor sidecar, started via DaprRunner.start(), loses a random-port race at boot: daprd assigns the same port to its API and internal gRPC servers, the internal listener fails with "bind: address already in use", and the runtime exits with "could not listen on any endpoint". The actor host is then dead, so the client's invoke_method fails with "did not find address for actor" and the expected output never appears.

PR #1030 already added this retry to the foreground run() path, but the background start() path was left uncovered. This applies the same exponential backoff retry there, reusing the existing failure markers. The captured log is only read once the process has exited (poll() is not None), so a healthy long-lived sidecar is never inspected and its append offset is left untouched.

Adds unit tests mirroring the existing run() coverage.

Fixes #1061

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

`test_demo_actor` flakes when the demo-actor sidecar, started via
`DaprRunner.start()`, loses a random-port race at boot: daprd assigns the
same port to its API and internal gRPC servers, the internal listener fails
with "bind: address already in use", and the runtime exits with
"could not listen on any endpoint". The actor host is then dead, so the
client's `invoke_method` fails with "did not find address for actor" and the
expected output never appears.

PR dapr#1030 already added this retry to the foreground `run()` path, but the
background `start()` path was left uncovered. Apply the same exponential
backoff retry there, reusing the existing failure markers. The captured log
is only read once the process has exited (`poll()` is not None), so a healthy
long-lived sidecar is never inspected and its append offset is left untouched.

Adds unit tests mirroring the existing `run()` coverage.

Fixes dapr#1061

Signed-off-by: Kshitiz Jain <kshitizj@gmail.com>
@kshitizj03 kshitizj03 requested review from a team as code owners June 20, 2026 14:16
@acroca acroca requested a review from Copilot June 30, 2026 10:21
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.15%. Comparing base (bffb749) to head (da1b63b).
⚠️ Report is 148 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1101      +/-   ##
==========================================
- Coverage   86.63%   82.15%   -4.48%     
==========================================
  Files          84      116      +32     
  Lines        4473     9578    +5105     
==========================================
+ Hits         3875     7869    +3994     
- Misses        598     1709    +1111     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces flakes in the examples test suite by making DaprRunner.start() resilient to a known transient Dapr sidecar startup failure (random-port bind collision), mirroring the retry behavior already implemented for DaprRunner.run().

Changes:

  • Add exponential-backoff retry logic to DaprRunner.start() when startup output matches the existing port-bind failure markers.
  • Add unit tests covering the retry and non-retry paths for start() using a background-process stand-in.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/examples/conftest.py Adds port-bind collision retry logic to DaprRunner.start() and introduces a helper to detect the failure safely for background sidecars.
tests/examples/test_dapr_runner.py Adds unit tests for start() retry behavior and introduces a fake background process for deterministic output simulation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/examples/conftest.py
Comment thread tests/examples/test_dapr_runner.py
@acroca acroca added this pull request to the merge queue Jun 30, 2026
Merged via the queue into dapr:main with commit bcb4b24 Jun 30, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: test_demo_actor flake

3 participants